{extend name="common/adminBase" /}
{block name="body"}
<style>
    .layui-input-inline{
        width: 400px !important;
    }
</style>
    <body >
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>角色选择
                        </label>
                        <div class="layui-input-inline">
                            <select name="rid" lay-verify="required" lay-filter="rid">
                                <option value="" selected=''> ---请选择---</option>
                                {volist name="data" id="v"}
                                <option value="{$v.id}"><?php echo $v['title']?></option>
                                {/volist}
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>真实姓名
                        </label>
                        <div class="layui-input-inline">
                            <input type="text"  name="name" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>手机号码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text"  name="phone" autocomplete="off" class="layui-input">
                        </div>
                
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>身份证号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text"  name="idcard" value="" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">登录系统的用户名</div>
                    </div>
             
                  <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>email邮箱
                        </label>
                        <div class="layui-input-inline">
                            <input type="text"  name="email" autocomplete="off" class="layui-input">
                        </div>
                  </div>
                  <div id="if_show">
                    {if $admin.lv!=3&&$admin.lv!=2}
                    <!--<div class="layui-form-item">-->
                    <!--    <label for="username" class="layui-form-label">-->
                    <!--        <span class="x-red">*</span>选择账号等级-->
                    <!--    </label>-->
                    <!--    <div class="layui-input-inline">-->
                    <!--        <select name="lv" lay-filter="lv" lay-search>-->
                    <!--            <option value="">---请选择---</option>-->
                    <!--            <option value="68">课题审核教育局</option>-->
                    <!--            <option value="3">学校</option>-->
                    <!--        </select>-->
                    <!--    </div>-->
                    <!--</div>-->

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span><span id="title">绑定机构</span>
                        </label>
                        <div class="layui-input-inline">
                            <select id="cid" name="cid" lay-search>
                            
                            </select>
                        </div>
                    </div>
                    {elseif $admin.lv==2 /}


                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span><span id="title">绑定机构</span>
                        </label>
                        <div class="layui-input-inline">
                            <select id="cid" name="cid" lay-search>
                            
                            </select>
                        </div>
                    </div>
                    {else/}
                        <div class="layui-form-item">
                              <label for="username" class="layui-form-label">
                                  <span class="x-red">*</span>评分对象
                              </label>
                              <div class="layui-input-inline">
                                    <select name="z_type">
                                        <option value="全部课题">全部课题</option>
                                        <option value="一般课题">一般课题</option>
                                        <option value="重点课题">重点课题</option>
                                    </select>
                              </div>
                          </div>
                    {/if}
                    </div>
                    <div id="change">
                        
                    </div>
                  <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>登录密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="c"  name="password" autocomplete="off" class="layui-input">
                        </div>

                  </div>

        
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          增加
                      </button>
                  </div>
              </form>
            </div>
        </div>
        <script>

            layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
                form.on("select(rid)",function(data){
                    console.log(data.value);
                    if(data.value==12){
                        $("#if_show").hide();
                        var html = '<div class="layui-form-item">'+
                                '<label for="username" class="layui-form-label">'+
                                  '<span class="x-red">*</span>评分对象'+
                              '</label>'+
                              '<div class="layui-input-inline">'+
                                    '<select name="z_type">'+
                                        '<option value="全部课题">全部课题</option>'+
                                        '<option value="一般课题">一般课题</option>'+
                                        '<option value="重点课题">重点课题</option>'+
                                    '</select>'+
                              '</div>'+
                          '</div>';
                        
                        $("#change").append(html);
                        form.render('select');
                    }else{
                        $("#if_show").show();
                        if(data.value==9){
                            lv = 2;
                            $("#title").html('所属区');
                        }else if(data.value==8){
                            lv = 3;
                            $("#title").html('绑定学校');
                        }else{
                            $("#if_show").hide();
                            return false;
                        }
                        $.ajax({
                            url:'/index/power/getgroup',
                            data:{lv:lv},
                            type:'post',
                            dataType:'json',
                            success:function(res){
                                $("#cid").html("");
                                $.each(res.msg, function(key, val) {
                                    if(lv==2){
                                       $('#cid').append(new Option(val.title+'教育局', val.id));
                                        form.render('select');
                                    }else{
                                        $('#cid').append(new Option(val.title, val.id));
                                        form.render('select');
                                    }
                                   
                                   
                                });
                               
                                // if(data.value==68){
                                //     // alert(123123);
                                //     $("#title").html('所属区');
                                // }else{
                                //     $("#title").html('绑定学校');
                                // }
                                // $("#cid").get(0).selectedIndex=0;
                            }
                        });
                        $("#change").empty();
                    }
                });
                form.on('select(lv)',function(data){
                    // console.log(data.value);
                    $.ajax({
                        url:'/index/power/getgroup',
                        data:{lv:data.value},
                        type:'post',
                        dataType:'json',
                        success:function(res){
                            $("#cid").html("");
                            $.each(res.msg, function(key, val) {
                                if(data.value==68){
                                // alert(123123);
                                
                                   $('#cid').append(new Option(val.title+'教育局', val.id));
                                    form.render('select');
                                }else{
                                    $('#cid').append(new Option(val.title, val.id));
                                    form.render('select');
                                }
                               
                               
                            });
                           
                            if(data.value==68){
                                // alert(123123);
                                $("#title").html('所属区');
                            }else{
                                $("#title").html('绑定学校');
                            }
                            // $("#cid").get(0).selectedIndex=0;
                        }
                    });
                });
                //监听提交
                form.on('submit(add)', function(data) {
                    console.log(data);
                    //发异步，把数据提交给php
                    $.ajax({
                        url:"",
                        data:data.field,
                        type:'post',
                        dataType:'json',
                        success:function (res) {
                            if (res.status==1){
                                layer.msg("增加成功",{icon:6,time:1500},function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            }else{
                                layer.alert(res.msg,function (index) {
                                    layer.close(index);
                                })
                            }
                        }
                    })

                    return false;
                });

            });

        </script>

    </body>

{/block}
